import request from "@/utils/request";

const recordApi = {
  // 分页请求
  getPage(page, pageSize, username) {
    return request({
      method: "get",
      url:
        "/record?page=" +
        page +
        "&pageSize=" +
        pageSize +
        "&username=" +
        username,
    });
  },
  // 删除记录
  deleteById(imageId) {
    return request({
      method: "get",
      url: "/record/delete?imageId=" + imageId,
    });
  },
  // 修改记录
  updateById(imageId, result1, result2, result3) {
    return request({
      method: "post",
      url: "/record/update",
      data: {
        imageId: imageId,
        record1: result1,
        record2: result2,
        record3: result3,
      },
    });
  },
  // 导出记录
  exportByUsername(username) {
    return request({
      method: "get",
      url: "/export?username=" + username,
      responseType: 'blob' // 返回类型 blob
    }).then(response => {
        const url = window.URL.createObjectURL(new Blob([response.data]));
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', 'records.xlsx');
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
      });
  },
};

export default recordApi;
